//import {Storage} from '@ionic/storage'

export class SLLocalStorageUtils {
    private static Instance: SLLocalStorageUtils;
    //private mLocalStorage:Storage;
    private static KEY_IP: string = "KEY_IP";
    private static KEY_PORT: string = "KEY_PORT";
    private static KEY_ASSIST:string="KEY_ASSIST";
    private static KEY_APPLY:string="KEY_APPLY";
    private static KEY_APPLY_DETAILS="KEY_APPLY_DETAILS";
    private static KEY_LOGIN_STATUS="KEY_LOGIN_STATUS";
    private static KEY_LOGIN_INFO="KEY_LOGIN_INFO";
    private static KEY_FILE_INFO="KEY_FILE_INFO";
    private static KEY_APPLE_FEE="KEY_APPLE_FEE";
    private static KEY_ZB_FEE="KEY_ZB_FEE";
    private static KEY_SX_FEE="KEY_SX_FEE";
    constructor() {
        if (SLLocalStorageUtils.Instance) {
            throw new Error("please use getInstance function");
        }
    }

    static getInstance() {
        if (!SLLocalStorageUtils.Instance) {
            SLLocalStorageUtils.Instance = new SLLocalStorageUtils();
        }
        return SLLocalStorageUtils.Instance;
    }
    async setAppleFee(val){
        await localStorage.setItem(SLLocalStorageUtils.KEY_APPLE_FEE,val);
    }
    async getAppleFee(){
        return await localStorage.getItem(SLLocalStorageUtils.KEY_APPLE_FEE);
    }
    async setAppleSXFee(val){
        await localStorage.setItem(SLLocalStorageUtils.KEY_SX_FEE,val);
    }
    async getAppleSxFee(){
        return await localStorage.getItem(SLLocalStorageUtils.KEY_SX_FEE);
    }
    async setZbFee(val){
        await localStorage.setItem(SLLocalStorageUtils.KEY_ZB_FEE,val);
    }
    async getZbFee(){
        return await localStorage.getItem(SLLocalStorageUtils.KEY_ZB_FEE);
    }
    async setFileInfo(val){
        await localStorage.setItem(SLLocalStorageUtils.KEY_FILE_INFO,JSON.stringify(val));
    }
    async getFileInfo(){
        return await JSON.parse(localStorage.getItem(SLLocalStorageUtils.KEY_FILE_INFO));
    }
    async clearFileInfo(){
        await localStorage.removeItem(SLLocalStorageUtils.KEY_FILE_INFO);
    }
    async setLoginInfo(val){
        await localStorage.setItem(SLLocalStorageUtils.KEY_LOGIN_INFO,JSON.stringify(val));
    }
    async getLoginInfo(){
        return await JSON.parse(localStorage.getItem(SLLocalStorageUtils.KEY_LOGIN_INFO));
    }
    async setLoginStatus(bool){
        await localStorage.setItem(SLLocalStorageUtils.KEY_LOGIN_STATUS,bool);
    }
    async getLoginStatus(){
       return await localStorage.getItem(SLLocalStorageUtils.KEY_LOGIN_STATUS);
    }
    async saveUrl(ip: string, port: string) {
        //await this.mLocalStorage.set(SLLocalStorageUtils.KEY_IP,ip);
        //await this.mLocalStorage.set(SLLocalStorageUtils.KEY_PORT,port);
        await localStorage.setItem(SLLocalStorageUtils.KEY_IP, ip);
        await localStorage.setItem(SLLocalStorageUtils.KEY_PORT, port);
    }
    async setAssist(val){
        await localStorage.setItem(SLLocalStorageUtils.KEY_ASSIST,JSON.stringify(val));
    }
    async setApply(val){
        await localStorage.setItem(SLLocalStorageUtils.KEY_APPLY,JSON.stringify(val));
    }
    async clearApply(){
        await localStorage.removeItem(SLLocalStorageUtils.KEY_APPLY);
    }
    async getApply(){
        return await JSON.parse(localStorage.getItem(SLLocalStorageUtils.KEY_APPLY));
    }
    async setApplyDetails(val){
        await localStorage.setItem(SLLocalStorageUtils.KEY_APPLY_DETAILS,JSON.stringify(val));
    }
    async getApplyDetails(){
        return await JSON.parse(localStorage.getItem(SLLocalStorageUtils.KEY_APPLY_DETAILS));
    }
    async clearApplyDetails(){
         await localStorage.removeItem(SLLocalStorageUtils.KEY_APPLY_DETAILS);
    }
    async getAssist(){
        return await JSON.parse(localStorage.getItem(SLLocalStorageUtils.KEY_ASSIST));
    }
    async clearAssist(){
         await localStorage.removeItem(SLLocalStorageUtils.KEY_ASSIST);
    }

    async get_Ip(): Promise<string> {
        return await localStorage.getItem(SLLocalStorageUtils.KEY_IP);
    }

    async get_Port(): Promise<string> {
        return await localStorage.getItem(SLLocalStorageUtils.KEY_PORT);
    }

    async destroy() {
        await localStorage.removeItem(SLLocalStorageUtils.KEY_ASSIST);
        await localStorage.removeItem(SLLocalStorageUtils.KEY_APPLY_DETAILS);
        await localStorage.removeItem(SLLocalStorageUtils.KEY_APPLY);
        await localStorage.removeItem(SLLocalStorageUtils.KEY_ASSIST);
        await localStorage.removeItem(SLLocalStorageUtils.KEY_LOGIN_STATUS);
        await localStorage.removeItem(SLLocalStorageUtils.KEY_LOGIN_INFO);
        await localStorage.removeItem(SLLocalStorageUtils.KEY_APPLE_FEE);
        await localStorage.removeItem(SLLocalStorageUtils.KEY_SX_FEE);
        await localStorage.removeItem(SLLocalStorageUtils.KEY_ZB_FEE);
        await localStorage.removeItem(SLLocalStorageUtils.KEY_FILE_INFO);
    }
}